import config from "config";

export const setEnvironments = () => {

    const prismaPort = config.get("prisma.port") || 4477;
    const mysqlPort = config.get("mysql.port") || 3377;
    const mysqlRootPassword = config.get("mysql.pootPassword");
    const envsPrisma = `PRISMA_PORT='${prismaPort}' ${getEnvPrismaUrl()}`;
    const envsMysql = `MYSQL_PORT='${mysqlPort}' MYSQL_ROOT_PASSWD='${mysqlRootPassword}'`;
    const envs = `${envsPrisma} ${envsMysql}`;

    console.log("Set the environment variables: ", process.env.HOST_NAME ? `HOST_NAME='${process.env.HOST_NAME}'` : "", envs, "\n");

    return envs;
}

export const getEnvPrismaUrl = () => {
    const envPrismaUrl = `PRISMA_URL=${getPrismaUrl()}`;
    return envPrismaUrl;
}

export const getPrismaUrl = () => {
    const hostName = process.env.HOST_NAME || "localhost";
    const prismaPort = config.get("prisma.port") || 4477;
    const prismaUrl = `http://${hostName}:${prismaPort}`;

    return prismaUrl;
}

const argv = process.argv.slice(2)
if (argv[0] === "getEnvUrls") {
    console.log(`${getEnvPrismaUrl()}`);
}